//
//  CTAdjustImageViewController.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/5/15.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTAdjustImageViewController.h"
#import "CTEditImageViewController.h"

//header
#import "CTHeader.h"

//view
#import "CTAdjustImageView.h"

//function
#import "CTDebugManager.h"
#import "MobClick.h"
#import "CTImageProcessing.h"

@interface CTAdjustImageViewController ()<CTAdjustImageViewDelegate>
{
    CTAdjustImageView * adjustImageView;
    UIImageView *_imageView;

}
@end

@implementation CTAdjustImageViewController
@synthesize adjustImage,type;


- (void)dealloc
{
    adjustImageView = nil;
    
    [CTDebugManager showDebugLogInfo:@"dealloc : CTAdjustImageViewController Is Removed!!!"];
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    //统计
    [MobClick beginLogPageView:@"CTAdjustImageViewController"];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    //统计
    [MobClick endLogPageView:@"CTAdjustImageViewController"];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    if (type == CTAdjustImageViewControllerTypeSetHead)
    {
        adjustImageView = [[CTAdjustImageView alloc] initWithType:CTAdjustImageViewTypeSetHead];
    }
    else
    {   adjustImageView = [[CTAdjustImageView alloc] initWithType:CTAdjustImageViewTypeDefault];
    }
    adjustImageView.delegate = self;
    
    [self.view addSubview:adjustImageView];
    
    adjustImageView.adjustImage = adjustImage;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



#pragma mark - view delegate -
-(void)nextStepAction:(CTAdjustImageView *)view withImg:(UIImage *)img
{
    if (type == CTAdjustImageViewTypeSetHead)
    {
        UIImage *image = [CTImageProcessing imageCompressionImg:img WithSize:CGSizeMake(100, 100)];
//        adjustImg = [CTImageProcessing imageCompressionImg:adjustImg WithSize:CGSizeMake(1024, 1024)];
                NSData * imgData1 = UIImagePNGRepresentation(image);
                long long int byteCount1 = imgData1.length;
        [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_SET_HEAD object:image];
        [self.navigationController dismissViewControllerAnimated:YES completion:^{
            
        }];
    }
    else
    {
        self.hidesBottomBarWhenPushed = YES;
        CTEditImageViewController * editImageViewVC = [[CTEditImageViewController alloc] init];

        editImageViewVC.editImage = img;
        [self.navigationController pushViewController:editImageViewVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
    }
    
    
}

-(void)backAction:(CTAdjustImageView *)view
{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
